This folder contains the code that can be used to generate the results reported in “Factor Momentum” by Robert D. Arnott, Vitali Kalesnik, and Juhani T. Linnainmaa.

INPUT DATA:
===========

The raw data used to run the tests in the paper were the monthly and daily CRSP databases and Compustat databases downloaded in early 2022 from WRDS. These databases at the time had the information up to the end of December 2021. 

The CRSP and Compustat data were merged following the convention that the accounting information is available six months after the end of the fiscal year.


PROCESSED DATA:
===============

All the estimates, as explained below, are done in the FactorMomentum20230102.do file. Folder ‘Data’ contains the input files necessary for running this code except for the Fama-French factors. The current vintage of these factors is available at https://mba.tuck.dartmouth.edu/pages/faculty/ken.french/data_library.html.


STATA and PYTHON CODE:
======================

The analyses in the paper were generated with a combination of Stata and Python files. 

The code assumes a Dropbox hierarchy for reading the input files and for saving various intermediate files, incl. the ones provided in the ‘Data’ folder. 

The files should be run in the following order:

File #1. ConstructFMFactors20201228.do is a Stata do-file that takes a merged CRSP/Compustat database, computes some additional predictors, and constructs standard and industry-neutral versions of various factors. Note: Not all predictors generated in this file are used in the paper. The key output files from this code are provided in the ‘Data’ folder. 

File #2. CharacteristicMomentum20220205.do is a Stata do-file that first outputs some characteristics into csv-files for computing clusters in Python. [Run File #3 here.] In then takes reads the resultant clusters from new csv-files and constructs various ‘characteristic momentum’ strategies, incl. the Lewellen (2002) strategies. The key output files from this code are provided in the ‘Data’ folder.

File #3. CharacteristicClusters.ipynb is a Jupyter notebook (Python) that constructs characteristics-based clusters using k-means and Ward clustering algorithms. (Return to File #2 after running this Python code.)

File #4. FactorMomentum20230102.do is a Stata do-file that runs the tests reported in the paper. In some cases, when there are multiple specifications, some of the input parameters need to be adjusted to generate all the results in the paper.